/*
Copyright (c) 2025 HeZongLun
NahidaProject is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan
PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <sql.h>
#include <sqlext.h>
#include <iostream>
#include <vector>
#include <map>
#include <functional>

namespace NahidaProject {
	class __declspec(dllexport) ODBC {
	private:
		SQLRETURN ret = NULL;
		SQLHENV henv = NULL;
		SQLHDBC hdbc = NULL;
		SQLHSTMT hstmt = NULL;

		std::map<std::string, std::function<void()>> transactionList;
	public:
		ODBC() {

		}

		~ODBC() {

		}
		int Connect(SQLCHAR* datasource, SQLCHAR* username, SQLCHAR* password);
		void RegisterTransaction(std::string transactionName, std::function<void()> transactionFunction);
		void InvokeTransaction(std::string transactionName);
		void UndoTransaction();
		void DeleteTransaction(std::string transactionName);
		int ExecuteSQLWithoutResult(SQLCHAR* sqlStatement);
		std::vector<std::vector<std::string>> ExecuteSQLWithResult(SQLCHAR* sqlStatement);
		void Close();
	};
}
